<?php

class M_position Extends MY_Model
{
	public function count_data()
	{
		return $this->db->count_all(parent::$pos_table);
	}
	
	public function fetch_positions($start,$limit)
	{
		$start = is_numeric($start) ? intval($start) : 0;
		$limit = is_numeric($limit) ? intval($limit) : 0;
	
		$query = $this->db->select('id,position_name,position_desc')
									->limit($start,$limit)
									->get(parent::$pos_table);
		return $query->num_rows() >= 1 ? $query->result() : FALSE;
	}

	public function insert($data)
	{
		if(!empty($data))
		{
			$this->db->insert(parent::$pos_table,$data);
			return $this->db->affected_rows() >= 1 ? TRUE : FALSE;
		}else{
			return FALSE;
		}
	}
	
	public function get_employee_array()
	{
		 $q =$this->db->select('id,position_name')
					  ->from(parent::$pos_table)
					  ->order_by('position_name','ASC')
					  ->get();
		if($q->num_rows() >= 1){
			$option[''] = 'Select Position';
			foreach($q->result() as $k)
			{
				$option[$k->id] = ucwords($k->position_name);
			}
			return $option;
		
		}else{
			return array('','No Position Available');
		} 
	}
	
	public function get_positions_by_dept_id($id)
	{
		$sql = "SELECT p.id,p.position_name,d.department_name 
				FROM ".parent::$pos_table." p
				LEFT JOIN ".parent::$dep_table." d ON d.id = p.dept_id
				WHERE d.id = ? ";
				
		$query = $this->db->query($sql,array($id));
		return $query->num_rows() >=1 ? $query->result() : FALSE;
	}









}